var express = require('express');
var router = express.Router();
var connection=require('../backjs/node_mysql.js')

router.post('/find_task_name',function (req,res) {
    console.log("获得前端查询委托单响应")
    var sql = "SELECT task_description FROM task where "+req.body.pj_id+"=task_pid"
    connection.query(sql,function (err,rs) {
        if(err){
            throw err}
        if (rs.length!=0)
        {
            console.log("不错，我已经成功的读取到了数据")

            req.message = rs[0];
            res.send(rs)
            console.log(rs)
            // res.send(200)
            // console.log(rs)

        }
        else
        {
            res.send(400)
        }
    })
});

router.post('/find_depute',function (req,res){
    console.log("还行，我捕获了亲求列表的信息")
    var sql  = "select task_id from task where task_description='"+req.body.task_description+"'"
        "' and task_pid = '"+ req.body.pj_id+"'"

    connection.query(sql,function (err,rs) {
        if(err){
            throw err}
        if (rs.length!=0)
        {
            console.log("不错，我已经成功的读取到了数据")
            res.send(rs[0])
            console.log('2222222' + rs[0].task_id)
        }
        else
        {
            res.send(400)
        }
    })
})


router.post('/find_depute_message',function (req,res){
    console.log("还行，我捕获了列表的请求")
    var sql  = "select wc_id,wc_tid,wc_pipeName,wc_pipeNum,wc_num,wc_spec," +
            "wc_techid from workcount where wc_tid = ?"
    var params = [req.body.task_id]
    console.log(params)
    connection.query(sql,params,function (err,rs) {
        if(err){
            throw err}
        if (rs.length!=0)
        {

            res.send(rs)
            console.log(rs)
                    }
        else
        {
            console.log("找不到啊")
            res.send(400)
        }
    })
})

router.post('/find_task',function (req,res){
    console.log("请求委托单的信息")
    var sql  = "select task_id,task_product,taskPaper_type,task_company,task_workNum,task_id from task where task_pid = ?"
    var params = [req.body.pj_id]

    connection.query(sql,params,function (err,rs) {
        if(err){
            throw err}
        if (rs.length!=0)
        {

            res.send(rs)
            console.log(rs)
        }
        else
        {
            console.log("我出了一些问题")
            res.send(400)
        }
    })
})


module.exports = router;